from machine import I2C,Pin
import time
import bmp280
def run():
    i2c = I2C(sda=Pin(14), scl=Pin(13))
    b = bmp280.BMP280(i2c)
    da = 0
    t=0
    try:
        while(1):
            da=da+1
            f = open("date"+str(da)+".txt",'r')
            f.close()
    except:
        f = open("date"+str(da)+".txt",'a')
        f.write('气压计数据记录\n')
        f.write("记录时间:  原始温度和气压:  高度:\n")
        f.close()
    while(True):
        time.sleep_ms(100)
        f = open("date"+str(da)+".txt",'a')
        t=t+1
        y = b.get()
        p = b.getPress()
        h = (101325-p)*9/100
        dat = (str(t/10)+"  "+str(y)+"  "+str(h)+"\n")
        f.write(dat)
        #print(h)
        f.close()
run()